<?php

	// general functions for use throughout the site
	
	// validate a date
	function is_date($string) {
		
		$stamp = strtotime($string);
		if(!is_numeric($stamp)) { return false; }
					   
		$m = date('m', $stamp);
		$d = date('d', $stamp);
		$y = date('Y', $stamp);
		
		if(checkdate($m, $d, $y)) { return true; }
		
		return false;
		
	}
	
	// validate a timestamp
	function is_time($string) {
		
		$pattern = '/^([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])/';
		if(preg_match($pattern, $string)) { return true; }
		
		return false;
		
	}
	
	// create select element based on a set/enum db field
	function createSelect($field) {
		
		$divs = $db->query("SHOW COLUMNS FROM teams LIKE '" . $field . "'")->fetchAll();
		$div = $divs[0]['Type'];                                                

		preg_match_all("/'(.*?)'/", $div, $enum_array);
		$enum_fields = $enum_array[1];
		
		$select = '';
		foreach($enum_fields as $type) $select .= '<option value="' . $type . '">' . $type . '</option>';	
		
		return $select;
		
	}

?>